import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:easy_go/pages/home/home_controller.dart';
import 'package:easy_go/ui/widgets/r_loading.dart';

class HomePage extends GetView<HomeController> {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('home page')),
      body: GetX<HomeController>(
        initState: (state) => Get.find<HomeController>().getAll(),
        builder: (controller) {
          return controller.postList.length < 1 ? const RLoading() : ListView.builder(
            itemBuilder: (context, index) => Card(
              color: Colors.white,
              child: ListTile(
                title: Text(controller.postList[index].title ?? 'a'),
                subtitle: Text(controller.postList[index].body ?? 'b'),
                onTap: ()=> controller.details(controller.postList[index]),
              ),
            ),
            itemCount: controller.postList.length,
          );
        },
      ),
    );
  }
}